﻿CREATE PROCEDURE [dbo].[usp_select_Reports_AlertSubscriptionsOverTime_ByService]
(
	@Application		varchar(255)	= null,
   @BeginDate			datetime      
   ,@EndDate			datetime      
   ,@Debug              bit              = 0
)
AS

SET NOCOUNT ON;

-- Bootstrap
DECLARE @DebugPrefix       varchar(10)
DECLARE @ErrorCode         int

SET @ErrorCode          = 0;
SET @DebugPrefix        = '>>> DEBUG: '


select 
	[Application], alerthistory.ServiceName,
	count([Application]) as FiredCount, 
	convert( varchar, alertsubscriptionhistory.[inserteddate], 101) as FiredDate
from alertsubscriptionhistory 
inner join alerthistory on alertsubscriptionhistory.alerthistoryid=alerthistory.alerthistoryid
where [Application] = @Application and alertsubscriptionhistory.[inserteddate] between @BeginDate and @EndDate
group by alerthistory.ServiceName,[application], convert( varchar, alertsubscriptionhistory.[inserteddate], 101)



SET NOCOUNT OFF;
